package com.burke.gwt.client;

import com.google.gwt.canvas.dom.client.Context2d;
import com.google.gwt.dom.client.ImageElement;
import com.google.gwt.user.client.ui.Image;

public class LED {

	final int x;
	final int y;
	final Digit digit;
	final LEDType type;
	final ImageElement offImg;
	final ImageElement onImg;
	boolean on = false;

	public LED(int x, int y, LEDType type, Digit digit) {
		this.x = x;
		this.y = y;
		this.digit = digit;
		this.type = type;//ball-b6b4b5 //gwt16.png
	//	this.onImg = new Image("../ANDROID-ICON.png").getElement().cast();
	//	this.onImg = new Image("../gwt16.png").getElement().cast();
		this.onImg = new Image("../google_android.png").getElement().cast();
		this.offImg = new Image("../ball-d9d9d9.png").getElement().cast();

	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public ImageElement getImg() {
		return offImg;
	}
	
	public void setOn(boolean on) {
		
		//if turning this off, add to floater group
		if(this.on == true && on == false) {
			digit.clock.floaterGroup.addFloater(
					(digit.clock.x + digit.x + x), 
					(digit.clock.y + digit.y + y), 
					type.ordinal());
		}
		
		this.on = on;
	}

	public void draw(Context2d context) {
	    context.save();
//	    context.translate(x, y);
	    if(on) {
	    	switch(type) {
	    	case ONE:
	    	case TWO:
	    	case THREE:
	    	default:
	    	context.drawImage(onImg, x, y);
	    	}
	    } else {
	    	context.drawImage(offImg, x, y);
		}
	    context.restore();
	}
}
